from flask import Blueprint
from .dev_info import DeviceInfoAPI
from .dev_log_info import DevLoginInfoAPI
from .commands import CommandAPI

api_bp = Blueprint('api',__name__)

deviceInfo_view   = DeviceInfoAPI.as_view('deviceInfo')
devLoginInfo_view = DevLoginInfoAPI.as_view('devLoginInfo')
command_view = CommandAPI.as_view('command')


# 分页查询
api_bp.add_url_rule('/deviceInfo/',defaults={'deviceInfo_id': None},view_func=deviceInfo_view,methods=['GET',])
# 添加新设备
api_bp.add_url_rule('/deviceInfo/',defaults={'deviceInfo_id': None},view_func=deviceInfo_view,methods=['POST',])
# 获取、删除、更新单台设备, deviceInfo_id=all则为全量查询
api_bp.add_url_rule('/deviceInfo/<deviceInfo_id>',view_func=deviceInfo_view,methods=['GET','DELETE','POST'])
# 重载，清空
# api_bp.add_url_rule('/deviceInfo/<any(reload, clear):operation>',view_func=deviceInfo_view,methods=['GET','DELETE'])


# 分页查询
api_bp.add_url_rule('/devLoginInfo/',defaults={'devLoginInfo_id': None},view_func=devLoginInfo_view,methods=['GET',])
# 添加新登录信息
api_bp.add_url_rule('/devLoginInfo/',defaults={'devLoginInfo_id': None},view_func=devLoginInfo_view,methods=['POST',])
# 获取、删除、更新单台设备的登录信息, devLoginInfo_id=all则为全量查询
api_bp.add_url_rule('/devLoginInfo/<devLoginInfo_id>',view_func=devLoginInfo_view,methods=['GET','DELETE','POST'])


# 发送命令
api_bp.add_url_rule('/command/',defaults={'command_id': None},view_func=command_view,methods=['GET',])
api_bp.add_url_rule('/command/',defaults={'command_id': None},view_func=command_view,methods=['POST',])
api_bp.add_url_rule('/command/<command_id>',view_func=command_view,methods=['GET','DELETE','POST'])